package group.ocr.Controller;

import group.ocr.Mapper.ImageMapper;
import group.ocr.Utils.OSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.xml.transform.Result;
import java.io.IOException;
@Slf4j
@RestController
public class OSSController {
    @Autowired
    private OSSUtils ossUtils;
    @Autowired
    private ImageMapper imageMapper;
    //文件上传阿里云
    @PostMapping("/getUrl")
    public String getUrl(MultipartFile file) throws IOException {
        String url= ossUtils.upload(file);
        log.info("上传文件的url为：{}",url);
        return url;
    }
    @PostMapping("upload")
    public String upload(MultipartFile file ,String title,String font,String author,String brief_introduction) throws IOException {
        String fileUrl= ossUtils.upload(file);
        String head_portrait_url="https://s1.mintiny.com/wlake/i/2024/12/12/3a75.png";
        imageMapper.addImage(title,font,author,fileUrl,head_portrait_url,brief_introduction);
        return "已上传作品："+file.getOriginalFilename();
    }
}
